﻿#pragma once
#include "windows.h"
#include <vector>
//接口
struct readerInterface
{
	bool (*openCom)(int portnum);//1 index
	void (*closeCom)();

	bool (*pgetx)(char* pdata) ;
	bool (*pgety)(char* pdata) ;
	bool (*pgetall)(char* pdata) ;
};
struct motorInterface
{
	bool (*openCom)(int portnum);//1 index
	void (*closeCom)();

	bool (*setDivide)(int d);
	bool (*forward)();//往前一步
	bool (*backword)();
	void (*fastSteps)(unsigned int steps,bool forward);
	void (*selAxis)(bool x);
};





class Point;


//struct mainAppInterface
//{
//	void (*clearChart)();
//	void (*addRed)(double x,double y);
//	void (*addBlue)(double x,double y);
//	void (*addData)(std::vector<Point*>&red,std::vector<Point*>&blue);
//	void (*Log2)(const wxString&msgs );
//	void (*Log3)(const wxString&msgs );
//};

class devices
{
public:
	devices(void);
	~devices(void);
	enum
	{
		state_run=1,
		state_pause,
		state_stop
	};

public:
	void openMotorPort(int com);
	void openReaderPort(int com);
	
	void closeMotorPort();
	void closeReaderPort();

	void start();


	readerInterface readDivice;
	motorInterface motor;

	wxFrame*app;

	int *pflag;
	wxString*pPara;
	std::vector<Point*> red,blue;
private:
	HANDLE pthread;
	HMODULE pMotor,pReader;

};


static DWORD _stdcall workTh(LPVOID p);

inline const wxArrayString getArray(int index,wxString ss)//index 0 base
{
	ss.Replace(wxT("["),wxT(""));
	ss.Replace(wxT(" "),wxT(""));//注意下面有空格
	//msg(ss);
	//[100; 1; 正向行走; 5] [1] [不返回; 1]
	//100; 1; 正向行走; 5] 1] 不返回; 1]
	wxArrayString as = wxStringTokenize(ss,wxT("]")); 
	
	return wxStringTokenize(as[index],wxT(";")); 
}
